﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace BitcoinLibrary
{
    /**
     * A Sha256Hash just wraps a byte[] so that equals and hashcode work correctly, allowing it to be used as keys in a
     * map. It also checks that the length is correct and provides a bit more type safety.
     */
    public class Sha256Hash /*implements Serializable */
    {
        public byte[] hash;

        public Sha256Hash(byte[] hash)
        {
            Debug.Assert(hash.Length == 32);
            this.hash = hash;
        }

        /** Returns true if the hashes are equal. */
        public override bool Equals(object other)
        {
            if (!(other is Sha256Hash)) return false;
            return Array.Equals(hash, ((Sha256Hash)other).hash);
        }

        /**
         * Hash code of the byte array as calculated by {@link Arrays#hashCode()}. Note the difference between a SHA256
         * secure hash and the type of quick/dirty hash used by the Java hashCode method which is designed for use in
         * hash tables.
         */
        public override int GetHashCode()
        {
            return hash.GetHashCode();
        }

        public override string ToString()
        {
            return Utils.bytesToHexString(hash);
        }
    }
}